<?php
/**
 * Dashboard panels Data records
 * TODO populateDefaults should call a method from the SSPanels Class. Code Redundancy.
 * @author rgodinho
 */
class SSPanelsData extends DataObject {
	
	static $db = array("column_id" => "Int", "sort_no" => "Int", "collapsed" => "Int",
	 					"title" => "Varchar(100)", "user_id" => "Int", "panel_id" => "Int");
	
	static $has_one = array();
	
	static $has_many = array();
	
	static $many_many = array();
	
	static $defaults = array();
	
	/**
	 * This method is called just before this object is
	 * written to the database.
	 */
	public function onBeforeWrite() {
		parent::onBeforeWrite();		
	}	
	
	/**
	 * overload so that the default data
	 */
	public function populateDefaults(){
		$colNum = SSPanels::$colNumber;
		$userID = 0;
		if(!DataObject::get('SSPanelsData')) {
				
			for($i= 0; $i < $colNum; $i++) {
				$this->write();
				$this->column_id = $i % 2;
				$this->sort_no = 1;
				$this->collapsed= 0;
				$this->title = 'Panel ' . $i;
				$this->user_id = $userID;
				$this->panel_id = $i;
				$this->write();
			}
		}				
	}	
}